home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / fs / read_write.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.6 KB  |  113 lines

  1. /*
  2.  *  linux/fs/read_write.c
  3.  *
  4.  *  Copyright (C) 1991, 1992  Linus Torvalds
  5.  *
  6.  * This file is subject to the terms and conditions of the GNU General Public
  7.  * License.  See the file README.legal in the main directory of this archive
  8.  * for more details.
  9.  */
  10.  
  11. #include <linux/types.h>
  12. #include <linux/errno.h>
  13. #include <linux/stat.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16.  
  17. #include <asm/segment.h>
  18.  
  19. /*
  20.  * Count is not yet used: but we'll probably support reading several entries
  21.  * at once in the future. Use count=1 in the library for future expansions.
  22.  */
  23. asmlinkage int sys_readdir(unsigned int fd, struct dirent * dirent, unsigned int count)
  24. {
  25.     int error;
  26.     struct file * file;
  27.     struct inode * inode;
  28.  
  29.     if (fd >= NR_OPEN || !(file = current->filp[fd]) ||
  30.         !(inode = file->f_inode))
  31.         return -EBADF;
  32.     error = -ENOTDIR;
  33.     if (file->f_op && file->f_op->readdir) {
  34.         error = verify_area(VERIFY_WRITE, dirent, sizeof (*dirent));
  35.         if (!error)
  36.             error = file->f_op->readdir(inode,file,dirent,count);
  37.     }
  38.     return error;
  39. }
  40.  
  41. asmlinkage int sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
  42. {
  43.     struct file * file;
  44.     int tmp = -1;
  45.  
  46.     if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode))
  47.         return -EBADF;
  48.     if (origin > 2)
  49.         return -EINVAL;
  50.     if (file->f_op && file->f_op->lseek)
  51.         return file->f_op->lseek(file->f_inode,file,offset,origin);
  52.  
  53. /* this is the default handler if no lseek handler is present */
  54.     switch (origin) {
  55.         case 0:
  56.             tmp = offset;
  57.             break;
  58.         case 1:
  59.             tmp = file->f_pos + offset;
  60.             break;
  61.         case 2:
  62.             if (!file->f_inode)
  63.                 return -EINVAL;
  64.             tmp = file->f_inode->i_size + offset;
  65.             break;
  66.     }
  67.     if (tmp < 0)
  68.         return -EINVAL;
  69.     file->f_pos = tmp;
  70.     file->f_reada = 0;
  71.     return file->f_pos;
  72. }
  73.  
  74. asmlinkage int sys_read(unsigned int fd,char * buf,unsigned int count)
  75. {
  76.     int error;
  77.     struct file * file;
  78.     struct inode * inode;
  79.  
  80.     if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
  81.         return -EBADF;
  82.     if (!(file->f_mode & 1))
  83.         return -EBADF;
  84.     if (!file->f_op || !file->f_op->read)
  85.         return -EINVAL;
  86.     if (!count)
  87.         return 0;
  88.     error = verify_area(VERIFY_WRITE,buf,count);
  89.     if (error)
  90.         return error;
  91.     return file->f_op->read(inode,file,buf,count);
  92. }
  93.  
  94. asmlinkage int sys_write(unsigned int fd,char * buf,unsigned int count)
  95. {
  96.     int error;
  97.     struct file * file;
  98.     struct inode * inode;
  99.  
  100.     if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
  101.         return -EBADF;
  102.     if (!(file->f_mode & 2))
  103.         return -EBADF;
  104.     if (!file->f_op || !file->f_op->write)
  105.         return -EINVAL;
  106.     if (!count)
  107.         return 0;
  108.     error = verify_area(VERIFY_READ,buf,count);
  109.     if (error)
  110.         return error;
  111.     return file->f_op->write(inode,file,buf,count);
  112. }
  113.